package com.example.cet4try.myDialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


import com.example.cet4try.R;

public class EditTextDialog extends Dialog {

    //private Context context;
    private TextView d_title;
    private EditText d_edit;
    private OnSelectListener onSelectListener = null;

    public EditTextDialog(Context context) {
        super(context, R.style.MyMessageDialog);
        //this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_text_dialog);
        iniView();
        //setCancelable(false);
        TextView bt_yes = findViewById(R.id.bt_yes);
        TextView bt_no = findViewById(R.id.bt_no);
        bt_yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onSelectListener != null)
                    onSelectListener.OnConfirm();
                dismiss();
            }
        });
        bt_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onSelectListener != null)
                    onSelectListener.onCancel();
                dismiss();
            }
        });
    }

    private void iniView() {
        d_title = findViewById(R.id.d_title);
        d_edit = findViewById(R.id.d_edit);
    }

    public void setTitle(String title){
        d_title.setText(title);
    }

    public void setText(String text){
        d_edit.setText(text);
    }

    public String getText(){
        return d_edit.getText().toString();
    }

    public interface OnSelectListener{
        void OnConfirm();
        void onCancel();
    }

    public void setOnSelectListener(OnSelectListener onSelectListener) {
        this.onSelectListener = onSelectListener;
    }

    public void show_t(String title,String text){
        super.show();
        setTitle(title);
        setText(text);
    }

}
